function [ D ] = createDomain( x, y )
%CREATEDOMAIN Summary of this function goes here
%   Detailed explanation goes here

n = size(x, 2);

ex = [(x(1:n-1) + x(2:n)) / 2, (x(n) + x(1)) / 2];
ey = [(y(1:n-1) + y(2:n)) / 2, (y(n) + y(1)) / 2];

% compute normal

% v1 = [x(1) - x(2), y(1) - y(2), 0];
% v2 = [x(3) - x(2), y(3) - y(2), 0];

up = [0, 0, 1];

nx = zeros(n, 1);
ny = zeros(n, 1);
l = zeros(n, 1);

for i = 1 : n
   i0 =  i;
   i1 = mod(i, n) + 1;
   v = [x(i1) - x(i0), y(i1) - y(i0), 0];
   
   nv = cross(up, v);
   nv = normalize(nv);
   
   nx(i) = nv(1);
   ny(i) = nv(2);
   l(i) = sqrt(v(1)^2 + v(2)^2);
end

D = struct('x', x, 'y', y, 'ex', ex, 'ey', ey, 'nx', nx, 'ny', ny, 'l', l);

end

